package com.robot.controller;

import com.robot.constant.Admin;
import com.robot.service.BuildTestService;
import com.robot.vo.ResponseMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created with IntelliJ IDEA.
 * User: li
 * Date: 2019/11/24
 * Time: 11:42
 * PROJECT：robot
 * PACKAGE: com.robot
 *
 * @author:55324936@qq.com To change this template use File | Settings | File Templates.
 */
@Controller
@RequestMapping("/buildTest")
@Slf4j
public class BuildTestController {

    @Autowired
    BuildTestService buildTestService;
    @RequestMapping("/buildTestByCase")
    public @ResponseBody
    ResponseMessage buildTestByCase(Integer[] caseIds){
        try{
          return  buildTestService.createBuildByTestCase(caseIds);
        }catch (Exception e){
            log.error("新增测试构建异常",e);
            return ResponseMessage.errorResponse("新增测试构建异常,请联系管理员");
        }
    }
    @RequestMapping("/runTestByInterface")
    public @ResponseBody
    ResponseMessage runTestByInterface(Integer[] interfaceIds){
        try{
            return  buildTestService.runTestByInterface(interfaceIds);
        }catch (Exception e){
            log.error("新增测试构建异常",e);
            return ResponseMessage.errorResponse("新增测试构建异常,请联系管理员");
        }
    }
    /**
     * 运行测试计划
     *
     * @param testPlanId
     * @return ResponseMessage
     */
    @RequestMapping("/buildTestPlan")
    public @ResponseBody
    ResponseMessage buildTestPlan(Integer testPlanId) {
        try {
            Integer buildTestId = buildTestService.saveBuildTestPlan(testPlanId);
            return ResponseMessage.successResponse(buildTestId);
        } catch (Exception e) {
            log.error("增加构建任务异常", e); return ResponseMessage.errorResponse("构建任务异常,"+ Admin.ADMIN_MESSAGE);
        }
    }
}
